package com.regent.central.bill.service.bean.mrp;

import com.regent.central.bill.core.mrp.ActionMaterialPurchase;
import com.regent.central.bill.repository.mrp.ActionMaterialPurchaseMapper;
import com.regent.central.bill.service.mrp.ActionMaterialPurchaseService;
import com.regent.central.infrastructure.common.Uid;
import com.regent.central.infrastructure.service.bean.DomainServiceBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Set;

@Service
public class ActionMaterialPurchaseServiceBean extends DomainServiceBean<ActionMaterialPurchaseMapper, ActionMaterialPurchase> implements ActionMaterialPurchaseService {

    @Resource
    private ActionMaterialPurchaseMapper actionMaterialPurchaseMapper;

    @Transactional
    @Override
    public Set<ActionMaterialPurchase> saveActions(Set<ActionMaterialPurchase> actionMaterialPurchases) {
        if (actionMaterialPurchases == null || actionMaterialPurchases.size() <= 0) {
            return actionMaterialPurchases;
        }

        for (ActionMaterialPurchase actionMaterialPurchase : actionMaterialPurchases) {
            actionMaterialPurchase.setId(Uid.random());
            actionMaterialPurchaseMapper.insertSelective(actionMaterialPurchase);
        }

        return actionMaterialPurchases;
    }
}